<style scoped>
.layui-row {
    overflow: hidden;
}

.select-item {
    width: 34.333333%;
    float: right;
}

.layui-row:after,
.layui-row:before {
    clear: none;
}
</style>

<template>
<div class="department">

    <form class="layui-form ">
        <div class="layui-col-lg4 select-item" style="text-align: right;width: auto">
            <div class="layui-inline" style="width: 200px">
                <input type="text" v-model="dailydata" autocomplete="off" name="dailydata" id="dailydata" placeholder="请选择日报日期" class="layui-input key">
            </div>
            <div class="layui-inline" style="width: 200px">
                <select v-model="srguid" name="srguid" id="srguid" lay-filter="storeroom" placeholder="请选择库房" class="layui-form-select">
                    <option value="">请选择库房</option>
                    <option v-for="item in storerooms " :value="item.guid">{{item.name}}</option>

                </select>
            </div>
            <div class="layui-inline" style="width: 200px">
                <select v-model="departid" name="departid" id="departid" placeholder="请选择班组" class="layui-input layui-unselect">
                    <option value="">请选择部门</option>
                    <option v-for="item in departments" :value="item.guid">{{item.name}}</option>
                </select>
            </div>
            <button type="button" class="layui-btn sou" @click="search">搜索</button>
        </div>
    </form>
    <table class="layui-table layui-form">

        <thead>
            <tr>
                <th>日报日期</th>
                <th>工厂名称</th>
                <th>计划名称</th>
                <th>班组名称</th>
                <th>库房名称</th>
                <th>成本</th>
                <th>收入</th>
                <th>利润</th>

                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr class="id9" v-for="(val, index) in productiondaily">
                <td>{{val.dailydate}}</td>
                <td>{{val.orgname}}</td>
                <td>{{val.planname}} </td>
                <td>{{val.departname}} </td>
                <td>{{val.srname}}</td>
                <td>{{val.cost}}</td>
                <td>{{val.income}}</td>
                <td>{{val.profit}}</td>

                <td><a href="javascript:;" @click="toPage(val.guid)">查看详情</a></td>
            </tr>
        </tbody>
    </table>

    <Pagination :cur="currentPage" :all="totalPage" :callback="turnPage"></Pagination>
</div>
</template>

<script>
import Pagination from '../common/Pagination.vue'
let qs = require('qs');
export default {
    name: 'ProductiondailyList',
    components: {
        Pagination
    },

    data() {
        return {
            departments: [],
            currentPage: 1,
            totalPage: 0,
            searchName: '',
            productiondaily: [],
            departid: "",
            dailydata: "",
            srguid: "",
            storerooms: [],
            departments: []
        }
    },
    mounted() {

        let that = this;
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;
            that.getPageData();
            that.getBaseInfo()
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#dailydata' //指定元素
            });

        });
    },
    updated: function () {
        layui.form.render('select');
        layui.form.render();

    },
    methods: {
        search: function () {
            this.getPageData('search');
        },
        turnPage: function (data) {
            this.currentPage = data;
            this.getPageData();
        },
        getPageData: function (type = '') {
            let that = this;
            let loader = layui.layer.load();

            let postData = {
                pageSize: 10
            };
            if (type != 'search') {
                postData.pageNo = that.currentPage;
            }

            that.srguid = $('#srguid').val();
            that.departid = $('#departid').val();
            that.dailydata = $('#dailydata').val();

            postData.huserid = sessionStorage.getItem('userid');
            postData.strid = that.srguid;
            postData.partid = that.departid;
            if (that.dailydata != "") {
                postData.plandate = that.dailydata;
            }
            $.ajax({
                url: '/produce/ProductionDaily!getList.action',
                type: "post",
                data: postData,
                dataType: "json",
                success: function (res) {
                    if (res.status == 'true') {
                        //分页数据赋值
                        that.currentPage = res.result.list.pageNo;
                        that.totalPage = res.result.list.pageCount;
                        that.productiondaily = res.result.list.rows;
                    } else {
                        that.alert("系统错误");
                    }
                },
                complete: function () {
                    layer.close(loader);
                }
            });
        },
        add: function () {
            this.$parent.switchPage('AddDepartment');
        },
        toPage: function (id) {
            this.$parent.gid = id;
            console.log(id);
            this.$parent.switchPage('Productiondaily');
        },
        getBaseInfo: function (type = '') {
            var that = this;
            let postData = {
                functionTypes: 8
            };
            $.ajax({
                url: '/sales/Salespermission!getPermisForStore.action',
                type: "post",
                data: postData,
                dataType: "json",
                success: function (res) {
                    if (res.msg == 'true') {
                        that.storerooms = res.storeroom;
                    } else {
                        that.toast('获取库房数据失败！');
                    }
                }
            });

            this.$post('/sales/Salespermission!getPermisForDepart.action', qs.stringify({
                    departype: 2
                }))
                .then(response => {
                    let data = response.data;
                    if (data.msg == 'true') {
                        this.departments = data.department;
                    } else {
                        this.toast('获取部门数据失败！');
                    }
                })
            layui.form.render("select");
        },
    }
}
</script>
